<?php
/**
 * Simple map.
 */
class SimpleMap {
   public function __construct() {
      $this->map = array();
   }

   public function clear() {
      $this->map = null;
      $this->map = array();
   }

   public function containsKey($key) {
      return array_key_exists($key, $this->map);
   }

   public function containsValue($value) {
      while($curValue = current($this->map)) {
         if($curValue == $value) {
            return true;
         }

         next($this->map);
      }

      return false;
   }

   public function equals($obj) {
      return false;
   }

   public function isEmpty() {
      return count($this->map) == 0;
   }

   public function get($key) {
//      if(array_key_exists($key, $this->map)) {
//         return $this->map[$key];
//      }
//      else
//         return null;
//      }
   }

   public function keys() {
      return array_keys($this->map);
   }

   public function put($key, $value) {
      if(!array_key_exists($key, $this->map)) {
         $this->map[$key] = $value;
         return null;
      }
      else {
         $tempValue = $this->map[$key];
         $this->map[$key] = $value;
         return $tempValue;
      }
   }

   public function remove($key) {
      $newMap = array();

      if(array_key_exists($key, $this->Map)) {
         $tempValue = $this->Map[$key];

         while($curValue = current($this->Map)) {
            if(!(key($this->Map) == $key)) {
               $newMap[key($this->Map)] = $curValue;
            }

            next($this->Map);
         }

         $this->Map = null;
         $this->Map = $newMap;
         return $tempValue;
      }
      else {
         return null;
      }
   }

   public function size() {
      return count($this->map);
   }

   public function values() {
      return array_values($this->map);
   }

   public function writeBody() {
      $str = "";

      foreach($this->map as $k=>$v) {
         $str .= $k . "=" . $v . "&";
      }

      return $str;
   }

   public function toString() {
      print_r($this->map);
   }

   private $map;
}
?>